1. Field of the Invention
The present invention is related to statistics management.
2. Description of the Related Art
A database system is one in which data is stored, retrieved, and processed. Data records in a relational database management system (RDBMS) in a computer are maintained in tables, which are a collection of rows all having the same columns. Each column maintains information on a particular type of data for the data records which comprise the rows. Tables in the database are searched using, for example, a Structured Query Language (SQL), which specifies search operations or predicates to perform on columns of tables in the database to qualify rows in the database tables that satisfy the search conditions.
Relational DataBase Management System (RDBMS) software using a Structured Query Language (SQL) interface is well known in the art. The SQL interface has evolved into a standard language for RDBMS software and has been adopted as such by both the American National Standards Institute (ANSI) and the International Standards Organization (ISO).
The database system typically stores statistics that may be useful for database processing. Statistics deficiencies, however, lead to poor performance of a SQL query. An RDBMS relies on statistical information residing in a system catalog to choose an access path for a SQL query. An access path may be described as a technique that is selected by an RDBMS optimizer for retrieving data from a database (e.g., an access path can involve the use of an index, a sequential scan, or a combination of the two) or as a path that is used to locate data that is specified in SQL statements. For the statistical information to be useful, the statistical information should be sufficient, consistent, and timely. However, there exist several statistics deficiencies that often cause a sub-optimal access path to be chosen. Some common categories of statistics deficiencies include: missing statistics, conflicting statistics, and obsolete/volatile statistics. Obsolete statistics refer to statistics that do not reflect the current state, while volatile statistics refer to statistics for data that changes often, which requires these statistics to be recollected frequently.
The missing statistics category represents query statistics that do not exist in the system catalog. The term “query statistics” may be described as statistics used to generate an efficient access path for execution of the query. Query statistics include, for example: table statistics, index statistics, column statistics (e.g., uniform distribution, non-uniform distribution, and distribution over range), and multiple column statistics (e.g., uniform distribution, non-uniform distribution, distribution over range, and correlation). Distribution statistics address data skew, while multi-column cardinality statistics address correlation.
The conflicting statistics category represents query statistics that exist in the system catalog, but for which there is some conflict between statistics.
The obsolete and/or volatile statistics category represents query statistics that exist in the system catalog, but for which the statistical information does not reflect the current status of the data. Because obsolete statistics do not portray data in the database accurately, obsolete statistics may lead to selection of a less efficient access path than if statistics were not available at all.
Traditionally, a database administrator (DBA) could periodically collect statistics for tables, indexes, and maybe some identified interesting columns and column groups (i.e., group of columns) for a database. When a DBA encounters a long running query, the DBA then may perform the following tasks manually: analyze the query; attempt to find all query statistics; check whether all query statistics exist in the system catalog; attempt to collect any missing statistics; check whether existing query statistics conflict with each other, and, if so, recollect these statistics to avoid conflicts; and, check whether obsolete statistics exists and, if so, either recollect or remove these statistics, depending on whether the obsolete statistics are needed. Some drawbacks of this manual approach are that the tasks are time-consuming and require a DBA to have specific knowledge in query tuning and about the specific optimizer. For a complex query, it may take hours or even days for an experienced DBA to manually perform statistics analysis. Moreover, because the process is complicated, it is unreasonable to expect a novice DBA to perform this activity correctly. Also, a DBA performs statistics analysis in a reactive way. Because the queries are becoming more and more complex in database environments, it is very difficult for DBAs to apply this manual approach in a database system (e.g., a production system). Moreover, oftentimes the manual effort to determine which statistics should be collected is prohibitive and complete and accurate statistics are often not collected, which leaves conventional optimizers to make optimization decisions with incomplete statistics.
The Microsoft® SQL Server™ 2000 product, available from Microsoft Corporation, stores statistical information regarding the distribution of values in indexed columns and for columns without indexes that are used in a predicate. The Microsoft® SQL Server™ 2000 product also indicates out-of-date or missing statistics as warnings. The Microsoft® SQL Server™ 2000 product updates statistical information periodically as the data in tables changes. This approach only eases some preliminary statistics deficiency problems. There are several drawbacks to the Microsoft® SQL Server™ 2000 product. For example, the Microsoft® SQL Server™ 2000 product does not take conflicting statistics into consideration. Additionally, the Microsoft® SQL Server™ 2000 product does not fully cover query statistics, such as multiple column related statistics. Multiple column related statistics are important because performance bottlenecks usually come from multiple column related statistics deficiencies for complex queries.
Thus, there is a need for improved statistics management.